\newcommand{\smallqueueoverhead}[2]{%

\draw[queuesty] (#1)node[right,xshift=.4cm,yshift=.-0.4cm]{\sffamily #2}-- ++(.2,.15)-- ++(1.15,0)-- ++(0,-.3)-- ++(-1.2,0)-- cycle;

\draw[fill=blue!90] (#1) ++ (.3,.15)rectangle +(.3,-.3);
\draw[fill=blue!70,postaction={pattern=north east lines, very thin, pattern color=white}] (#1) ++ (.65,.15)rectangle +(.3,-.3);
\draw[fill=blue!70,postaction={pattern=north east lines, very thin, pattern color=white}] (#1) ++ (1,.15)rectangle +(.3,-.3);}

\newcommand{\bigqueueoverhead}[2]{%
\draw[queuesty] (#1)node[right,xshift=.2cm]{\sffamily #2}-- ++(.3,.3)-- ++(.8,0)-- ++(0,-.6)-- ++(-.8,0)-- cycle;}

\newcommand{\overheadsSuffered}[2]{%
\begin{tikzpicture}[
  xscale=#1,
  yscale=#2,
  every node/.append style={transform shape},
  queuesty/.style={fill=white, very thick, font=\tiny},
  srpsty/.style={fill=white, draw, circle, text width=.17cm, font=\tiny, very thick},
  numsty/.style={text width=.1cm, font=\tiny},
  arrow/.style={->},
  littletext/.style={font=\sffamily\tiny,inner sep=0pt,outer sep=-2pt,fill=white},
  ressty/.style={fill=red!30, draw, very thick, rounded corners=5pt},
  emptytask/.style={rectangle, minimum width=.7cm,font=\footnotesize},
  taskHolder/.style={fill=blue!90, draw, rectangle, minimum width=.7cm,font=\footnotesize},
  taskWaiting/.style={fill=blue!70, draw, rectangle, minimum width=.7cm,font=\footnotesize,postaction={pattern=north east lines, very thin, pattern color=white}},
  taskAccess/.style={fill=blue!30, draw, rectangle, minimum width=.7cm,font=\footnotesize},
  taskNotAccess/.style={fill=white, draw, rectangle, minimum width=.7cm,font=\footnotesize}]

\def\blockdim{(.7,.25)}

\draw[arrow] (2.2,5.25) to[out=90,in=0] (2.35,6.6);

\begin{scope}[xshift=2.2cm, yshift=5cm]
  \coordinate (SRPnode) at (0,0);

  \draw[dashed,purple] (-1.5,-0.78) -- (0.27,-0.78);

  \node[taskNotAccess]  (T1)  at (-0.8,-0.50)  {};
  \node[emptytask]      (TP1) at (-0.8,-0.75) {$\cdots$};
  \node[taskWaiting]     (T2)  at (-0.8,-1.00)  {};
  \node[emptytask]      (TP1) at (-0.8,-1.25) {$\cdots$};
  \node[taskAccess]     (T3)  at (-0.8,-1.50)  {};
  \node[emptytask]      (TP1) at (-0.8,-1.75) {$\cdots$};
  \node[taskNotAccess]  (T4)  at (-0.8,-2.00)  {};
  \node[emptytask]      (TP1) at (-0.8,-2.25) {$\cdots$};
  \node[taskNotAccess]     (T5)  at (-0.8,-2.50)  {};

  \draw[dashed, thin] ([shift={(-1.5,0)}]SRPnode) node[right,xshift=.1cm,littletext]{Partition$_2$} rectangle ([shift={(.3,-.15)}]T5.south-|SRPnode.east);

  \node[srpsty] (SRP) at (SRPnode) {}; \node[font=\sffamily\tiny] at(SRPnode.west){SRP};
  \draw[arrow] (T2.east) to[out=0,in=270] (SRP.south);

  \draw[red] ([shift={(-.4,.17)}]T2) rectangle ([shift={(.25,-.05)}]T5.south-|T5.east);

  \draw[arrow,red] (-0.35,-3.05) -- ([shift={(.1,-.05)}]T5.south-|T3.east);

\end{scope}

% SMUSSARE UN POCHETTO LA TRAIETTORIA??
\draw[arrow] (1.8,5.80) to[out=10,in=0] (2.35,6.55);
\draw (0,5.20) to[out=90,in=190] (1.8,5.80);

\begin{scope}[yshift=5cm]
  \coordinate (SRPnode) at (0,0);

  \draw[dashed,purple] (-1.5,-0.78) -- (0.27,-0.78);

  \node[taskNotAccess]  (T1)  at (-0.8,-0.50)  {};
  \node[emptytask]      (TP1) at (-0.8,-0.75) {$\cdots$};
  \node[taskAccess]     (T2)  at (-0.8,-1.00)  {};
  \node[emptytask]      (TP1) at (-0.8,-1.25) {$\cdots$};
  \node[taskHolder]     (T3)  at (-0.8,-1.50)  {};
  \node[emptytask]      (TP1) at (-0.8,-1.75) {$\cdots$};
  \node[taskNotAccess]  (T4)  at (-0.8,-2.00)  {};
  \node[emptytask]      (TP1) at (-0.8,-2.25) {$\cdots$};
  \node[taskAccess]     (T5)  at (-0.8,-2.50)  {};

  \draw[dashed, thin] ([shift={(-1.5,0)}]SRPnode) node[right,xshift=.1cm,littletext]{Partition$_1$} rectangle ([shift={(.3,-.15)}]T5.south-|SRPnode.east);

  \node[srpsty] (SRP) at (SRPnode) {}; \node[font=\sffamily\tiny] at(SRPnode.west){SRP};
  \draw[arrow] (T3.east) to[out=0,in=270] (SRP.south);

   \draw[red] ([shift={(-.4,.17)}]T2) rectangle ([shift={(.25,-.05)}]T5.south-|T3.east) node[right,fill=none,red,littletext, yshift=.2cm]{(ii)};

  \draw[red] ([shift={(-.6,.2)}]T3) node[right,fill=none,red,littletext]{(i)} rectangle ([shift={(.05,-.05)}]T3.south-|T3.east);

  \draw[arrow,red] (-0.35,-3.2) -- ([shift={(.1,-.05)}]T5.south-|T3.east);

  \draw[red]  (-0.35,-3.2) node[right,fill=white,red,littletext,xshift=2.1cm]{(iii)} -- (4.05,-3.2);

\end{scope}

\draw[arrow] (4.4,5.25) to[out=90,in=0] (2.35,6.65);

\begin{scope}[xshift=4.4cm, yshift=5cm]
  \coordinate (SRPnode) at (0,0);

  \draw[dashed, purple] (-1.5,-1.28) -- (0.27,-1.28);

  \node[taskNotAccess]  (T1)  at (-0.8,-0.50)  {};
  \node[emptytask]      (TP1) at (-0.8,-0.75) {$\cdots$};
  \node[taskNotAccess]  (T2)  at (-0.8,-1.00)  {};
  \node[emptytask]      (TP1) at (-0.8,-1.25) {$\cdots$};
  \node[taskAccess]     (T3)  at (-0.8,-1.50)  {};
  \node[emptytask]      (TP1) at (-0.8,-1.75) {$\cdots$};
  \node[taskWaiting]    (T4)  at (-0.8,-2.00)  {};
  \node[emptytask]      (TP1) at (-0.8,-2.25) {$\cdots$};
  \node[taskAccess]     (T5)  at (-0.8,-2.50)  {};

  \draw[dashed, thin] ([shift={(-1.5,0)}]SRPnode) node[right,xshift=.1cm,littletext]{Partition$_3$} rectangle ([shift={(.3,-.15)}]T5.south-|SRPnode.east);

  \node[srpsty] (SRP) at (SRPnode) {}; \node[font=\sffamily\tiny] at(SRPnode.west){SRP};
  \draw[arrow] (T4.east) to[out=0,in=270] (SRP.south);

  \draw[red] ([shift={(-.4,.17)}]T3) rectangle ([shift={(.25,-.05)}]T5.south-|T5.east);

  \draw[arrow,red] (-0.35,-3.2) -- ([shift={(.1,-.05)}]T5.south-|T3.east);

\end{scope}

\begin{scope}[xshift=6.6cm, yshift=5cm]
  \coordinate (SRPnode) at (0,0);

  \node[taskNotAccess]  (T1)  at (-0.8,-0.50)  {};
  \node[emptytask]      (TP1) at (-0.8,-0.75) {$\cdots$};
  \node[taskNotAccess]  (T2)  at (-0.8,-1.00)  {};
  \node[emptytask]      (TP1) at (-0.8,-1.25) {$\cdots$};
  \node[taskNotAccess]  (T3)  at (-0.8,-1.50)  {};
  \node[emptytask]      (TP1) at (-0.8,-1.75) {$\cdots$};
  \node[taskNotAccess]  (T4)  at (-0.8,-2.00)  {};
  \node[emptytask]      (TP1) at (-0.8,-2.25) {$\cdots$};
  \node[taskNotAccess]  (T5)  at (-0.8,-2.50)  {};

  \draw[dashed, thin] ([shift={(-1.5,0)}]SRPnode) node[right,xshift=.1cm,littletext]{Partition$_4$} rectangle ([shift={(.3,-.15)}]T5.south-|SRPnode.east);

  \node[srpsty] (SRP) at (SRPnode) {}; \node[font=\sffamily\tiny] at(SRPnode.west){SRP};
\end{scope}

\begin{scope}[yshift=7cm]
\draw[ressty] (-0.5,-.65) rectangle +(1.5,.5) node[midway, font=\tiny]{resource};
\smallqueueoverhead{1.0,-0.4}{FIFO}
\draw[|-|] (1.2, -.02) -- ++(1.15,0)node[midway,fill=white,font=\tiny]{$3$};
\end{scope}

\begin{scope}[yshift=7.5cm]
  \draw[taskNotAccess]   (-1.5,0) node[right, xshift=0.8cm, yshift=.125cm]{\tiny Doesn't need resource} rectangle +\blockdim;
  \draw[taskAccess]   (-1.5,0.5) node[right, xshift=0.8cm, yshift=.125cm]{\tiny Needs resource access} rectangle +\blockdim;
  \draw[taskHolder]   (2,0.5) node[right, xshift=0.8cm, yshift=.125cm]{\tiny Lock Holder} rectangle +\blockdim;
  \draw[taskWaiting]   (2,0) node[right, xshift=0.8cm, yshift=.125cm]{\tiny Queued and waiting} rectangle +\blockdim;

  \draw[dashed,purple] (4.5,0.6) node[right, xshift=0.7cm, black]{\tiny Local ceiling} -- +(0.7,0);
\end{scope}

\end{tikzpicture}}
